package com.pjedu.nbmallwebsitesystem.config;

import com.pjedu.nbmalluser.mapper.MallUserMapper;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.servlet.DispatcherType;

@Configuration
public class LoginConfig {
    @Resource
    MallUserMapper mallUserMapper;
    @Bean
    public FilterRegistrationBean loginFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        LoginFilter loginFilter = new LoginFilter();
        loginFilter.setMallUserMapper(mallUserMapper);
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(loginFilter);
        registration.setName("loginFilter");
        registration.setOrder(1);
        // 商城页面登陆拦截
        registration.addUrlPatterns(new String[]{
                "/shop-cart/*","/saveOrder","/orders","/orders/*",
                "/order/*","/personal/*","/personal/updateInfo","/payPage",
                "/cart-order"
        });
        return registration;
    }
}
